package edu.suda.xsap.controller;

import edu.suda.xsap.service.LoginService;
import edu.suda.xsapadminutils.common.Result;
import edu.suda.xsapadminvo.EmployeeVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @GetMapping("/captcha")
    public void generateCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
        loginService.generateCaptcha(request, response);
    }

    @PostMapping()
    public Result login(@RequestBody EmployeeVO employeeVO) {
        return loginService.login(employeeVO);
    }

    @PostMapping("/register")
    public Result register(@RequestBody EmployeeVO employeeVO) {
        return loginService.register(employeeVO);
    }

}
